package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.domain.Travelcontent;
import cn.wolfcode.trip.base.query.TravelObject;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.service.ITravelService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("travel")
public class TravelController {

    @Autowired
    private ITravelService travelService;
    @Autowired
    private IStrategyService strategyService;

    @RequestMapping("audit_list")
    public String list(Model model, @ModelAttribute("qo") TravelObject qo){
        qo.setState(Travel.STATE_WAIT);
        qo.setIsPublic(true);
        qo.setOrderBy("t.createTime");

        model.addAttribute("pageInfo",travelService.query(qo));

        return "travel/audit_list";
    }

    //查询热门操作
    @RequestMapping("hot")
    public String hot(Model model, @ModelAttribute("qo") TravelObject qo){
        System.out.println(qo);
        qo.setState(Travel.STATE_HOT);
        qo.setIsPublic(true);
        qo.setOrderBy("t.createTime");
        model.addAttribute("pageInfo",travelService.queryByState(qo));
        model.addAttribute("strategys",strategyService.listAll());
        return "travel/hot";
    }

    @RequestMapping("getContentById")
    @ResponseBody
    public Travelcontent getContentById(Long id) {
        return travelService.getContentById(id);
    }

    @RequestMapping("changeStateById")
    @ResponseBody
    public JSONResult changeStateById(Travel travel){

        travelService.changeStateById(travel);
        return new JSONResult();
    }
}
